import { selectors } from '../config.js';
import { BaseCardExtractor } from './base-card-extractor.js';

// 提取旧版卡片数据
export function extractOldCard(cardElement) {
  // 添加卡片标题标签
  const cardTitle = cardElement.querySelector(selectors.cardName)?.textContent.trim() || '旧版卡片';
  const titleLabel = document.createElement('div');
  titleLabel.textContent = cardTitle;
  titleLabel.className = 'auto-old-card-label';
  titleLabel.style.cssText = `
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 16px;
    font-weight: bold;
    color: #d46b08;
    background: #f5f5f5;
    border: 2px solid #d46b08;
    border-radius: 0;
    padding: 2px 6px;
    z-index: 9999;
    pointer-events: none;
  `;
  cardElement.style.position = 'relative';
  cardElement.appendChild(titleLabel);

  // 添加卡片样式
  cardElement.style.backgroundColor = 'hsla(30, 70%, 80%, 0.3)';
  cardElement.style.border = '1px solid #d46b08';
  cardElement.style.borderRadius = '6px';
  cardElement.style.padding = '8px';
  cardElement.style.margin = '4px 0';

  const label = cardElement.querySelector(selectors.cardName)?.textContent.trim() || '';
  const value = cardElement.querySelector(selectors.cardValue)?.textContent.trim() || '';
  const changeTitle = cardElement.querySelector(selectors.cardChangeTitle)?.textContent.trim();
  const changeValue = cardElement.querySelector(selectors.cardChangeValue)?.textContent.trim();
  
  if (label || value) {
    const card = { label, value };
    if (changeTitle && changeValue) {
      card[changeTitle] = changeValue;
    }
    return card;
  }
  return null;
}

export class OldCardExtractor extends BaseCardExtractor {
  constructor() {
    super({
      card: selectors.card,
      name: selectors.cardName,
      value: selectors.cardValue,
      changeTitle: selectors.cardChangeTitle,
      changeValue: selectors.cardChangeValue
    });
  }
} 